﻿<?php

include 'dbconnect.php';
$dbcnx = dbconnect();


function drawRecordsTable($type)
{
  $query = sprintf("SELECT record.caption, record.theme, user.name, record.date, record.id 
                    FROM records record, users user
                    WHERE (record.type = %d AND record.author_id = user.id) ORDER BY record.date DESC",
                    $type);
  $news = mysql_query($query);
  if (!$news)
  {
    //die('Беда=( ' .mysql_error());
  }
  $rownum = mysql_num_rows($news);
  
  echo "<table width = \"100%\" bordercolor = \"green\">";
  echo "<tr>";
  
  $refNews = sprintf("index.php?type=1");
  $refSugg = sprintf("index.php?type=2"); 
  if ($type == 1)
  {
    
    echo "<td bgcolor = \"white\" align = \"center\"><font size = \"5\" color = \"black\">";
    echo "<a href = ";
    echo $refNews;
    echo ">";
    echo "Новости";
    echo "</font></td>";
    
    echo "<td bgcolor = \"green\" align = \"center\"><font size = \"5\" color = \"white\">";
    echo "<a href = ";
    echo $refSugg;
    echo ">"; 
    echo "Заявки";
    echo "</font></td>";
  }
  else
  {
    echo "<td bgcolor = \"green\" align = \"center\"><font size = \"5\" color = \"white\">";
    echo "<a href = ";
    echo $refNews;
    echo ">";
    echo "Новости";
    echo "</font></td>";
    
    echo "<td bgcolor = \"white\" align = \"center\"><font size = \"5\" color = \"black\">";
    echo "<a href = ";
    echo $refSugg;
    echo ">";
    echo "Заявки";
    echo "</font></td>";
  }
  echo "</tr>";
  
  for ($i = 0; $i < $rownum; $i++) 
  {
      echo "<tr><th colspan = \"2\">";
      echo "<table width = \"100%\" bordercolor = \"black\">";
      echo "<tr><td></td><td></td><td></td></tr>";
      $ref = sprintf("news_view.php?id=%d", mysql_result($news, $i, 'id'));
      echo "<tr><td align = \"left\"><a href = ";
      echo $ref;
      echo "><font size = \"4\"><b><u>";
      echo mysql_result($news, $i, 'caption');
      echo "</b></u></font></a></td></tr>";
      echo "<tr><th colspan = \"3\" align = \"left\">";
      echo mysql_result($news, $i, 'theme');
      echo "</th></tr>";
      echo "<tr><td align = \"left\">";
      echo mysql_result($news, $i, 'name');
      echo "</td><td>&nbsp</td><td align = \"right\">";
      echo mysql_result($news, $i, 'date');
      echo "</td></tr></table></th></tr>";

      if ($_SESSION['isAdmin'])
      {	
		
		echo "<tr>";
      	echo "<td bgcolor = \"white\">";
		$iID = mysql_result($news, $i, 'record.id');
		echo "<form id=\"form$iID\" action=\"delete_record.php\" method=\"post\">";
        echo "<input name=\"id_deleted\" form=\"form$iID\" value=\"$iID\" type=\"hidden\"/>";
		
		echo "<input name=\"type\" form=\"form$iID\" value=\"$type\" type=\"hidden\"/>";


        echo "<input type=\"submit\" form=\"form$iID\" value=\"Удалить\" />";
		echo "</form>";
		//echo $iID;

    echo "</td></tr>";
      }
                                
  }
  echo "</table>";
}


?>

